package com.changgou.system;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@SpringBootApplication
@EnableEurekaClient
public class GatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class,args);
    }
    //通过网关达到请求限流的作用

    @Bean
    public KeyResolver ipKeyResolver(){
        return  new KeyResolver() {
            @Override
            public Mono<String> resolve(ServerWebExchange exchange) {
                //此配置将访问这个goods的ip起限流的作用 若配置的是一个字符串 表示对整个goods起限流的作用
                //宁外 限流可以在配置文件中配置多个对多个对复制起限流的作用
                return Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
            }
        };
    }

}
